package DesignPattern.observePattern;

import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;

/**
 *观察者模式�
 */
public class Monitored extends Observable {

	public void sendMessage(String str){
		this.setChanged();
		this.notifyObservers(str);
	}
	
	public static void main(String[] args) {
		Monitored monitored = new Monitored();
		
		Watcher1 watcher1 = new Watcher1();
		Watcher2 watcher2 = new Watcher2();

		monitored.addObserver(watcher1);
		monitored.addObserver(watcher2);

		monitored.sendMessage("hello");
		
		ArrayList list=new ArrayList();
//		list.iterator()
	}
}

/**
 * �۲���1
 */
class Watcher1 implements Observer {

//	@Override
	public void update(Observable o, Object arg) {
		System.out.println("Watcher1 receive:" + (String)arg);
	}
}
/**
 * �۲���2
 */
class Watcher2 implements Observer {

//	@Override
	public void update(Observable o, Object arg) {
		System.out.println("Watcher2 receive:" + (String)arg);
	}
}